Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@poppinss/colors
Advanced tools
A wrapper on top of kleur with ability to write test against the color functions
Wrapper on top of Kleur with support for testing color calls.
This module is a wrapper on top of Kleur to make it easier to test the output generated using the kleur API. The API exposed is 100% the same as kleur.
Have you ever wonder, how to test the output of function calls like the following?
import { bgRed, white } from 'kleur'
assert.equal(bgRed().white('Error'), 'Error') // fails
Well, you can make use of modules like strip-ansi to strip the ansi codes and get back the plain string.
import { bgRed, white } from 'kleur'
import stripAnsi from 'strip-ansi'
assert.equal(stripAnsi(bgRed().white('Error')), 'Error') // passes
However, this module takes a step forward with a fake colors API, that you can use during testing to reliably test the output.
import { FakeColors } from '@poppinss/colors'
const colors = new FakeColors()
assert.equal(colors.bgRed().white('Error'), 'bgRed(white(Error))') // passes
Install the package from npm registry as follows:
npm i @poppinss/colors
# yarn
yarn add @poppinss/colors
and then use it as follows:
import { Colors } from '@poppinss/colors'
const colors = new Colors()
// API same as kleur from here
When wring tests, you can make your code rely on FakeColors
object instead of the Colors
object. For example:
import { FakeColors } from '@poppinss/colors'
const colors = new FakeColors()
// API same as kleur from here
The Raw
implementation exposes the same API as kleur, but does not apply any formatting/colors to the output string. You can use the raw implementation when the terminal does not support colors. For example:
import { Colors, Raw } from '@poppinss/colors'
import { level } from 'color-support'
const colors = level > 0 ? new Colors() : new Raw()
colors.red('hello world')
Finally, there is a method called getBest
to get the best available implementation instance for your runtime.
import { getBest } from '@poppinss/colors'
const colors = getBest(false)
The getBest
method returns following outputs
true
.FAQs
A wrapper on top of kleur with ability to write test against the color functions
The npm package @poppinss/colors receives a total of 35,833 weekly downloads. As such, @poppinss/colors popularity was classified as popular.
We found that @poppinss/colors demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.